import { IsPhoneNumber } from 'class-validator'
import { Column, Entity, Index } from 'typeorm'
import { BaseEntity } from './BaseEntity'

@Entity()
@Index(['wxNickname', 'phoneNumber', 'wechatNumber', 'qq', 'sex', 'name'])
export class User extends BaseEntity {

  @Column({
    length: 32,
    comment: '用户中文名',
  })
  public name!: string

  @Column({
    length: 32,
    name: 'wx_nickname',
    comment: '微信昵称',
  })
  public wxNickname!: string

  @Column({
    length: 32,
    name: 'open_id',
    comment: '微信openid',
  })
  public openId!: string

  @Column({
    length: 32,
    name: 'unionid',
    comment: '微信openid',
  })
  public unionid!: string

  @Column({
    name: 'wx_avatar',
    comment: '微信头像',
  })
  public wxAvatar!: string

  // 性别 0：未知、1：男、2：女
  @Column()
  public sex!: 0 | 1 | 2

  @Column({
    comment: '手机号',
    name: 'phone_number'
  })
  @IsPhoneNumber('CH')
  public phoneNumber!: number

  @Column({
    comment: '微信号',
    name: 'wechat_number'
  })
  public wechatNumber!: string

  @Column({
    comment: 'qq号',
    name: 'qq'
  })
  public qq!: number

  @Column({ name: 'is_patriarch', default: 0, comment: '是否是学生家长' })
  public isPatriarch!: 0 | 1

}

// 我们对每一个 model 实现一个 query 这样可以实现封装的操作每一个 model
export class UserQuery {
  public insert() {

  }
}
